package com.shadt.cloud.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class SortUtil {
	public static Set<Object> sortByValue(Set<Object> set) {
		List<Object> setList = new ArrayList<Object>(set);
		Collections.sort(setList, new Comparator<Object>() {
			@Override
			public int compare(Object o1, Object o2) {
				return o1.toString().compareTo(o2.toString());
			}
		});
		set = new LinkedHashSet<Object>(setList);// 这里注意使用LinkedHashSet
		return set;
	}
	public static void main(String[] args) {
		Set<Object> keySet = new HashSet<Object>();
		keySet.add("appname");
		keySet.add("time");
		keySet.add("key");
		keySet.add("start");
		keySet.add("size");
		keySet.add("sign");
		Set<Object> s = sortByValue(keySet);
		for (Object object : s) {
			System.out.println(object);
		}
	}
	
}
